#pragma once
#include "FWGame.h"
#include "FWTexture.h"
#include <d3dx9.h>
class FWGame;
class FWGraphic
{
protected:
	FWGame* _gameObject;
	LPD3DXSPRITE _sprite;
	D3DXMATRIX* _tranform;
	LPDIRECT3DSURFACE9 backbuffer;	
	D3DXVECTOR2 _worldPositionToViewport(D3DXVECTOR2 world,D3DXVECTOR2 center);	


	LPD3DXFONT font;
	char* fontFace;
	D3DXVECTOR2 fontSize;
	D3DXFONT_DESC fontDesc;

#pragma region Toi uu hoa
	D3DXVECTOR4 vp_pos;
	D3DXVECTOR3 _world;


	D3DXVECTOR3 nDraw_center;
	D3DXVECTOR3 nDraw_position;

	D3DXVECTOR2 tDraw_vp_pos;
	D3DXVECTOR2 tDraw_vec2_tmp;

	D3DXVECTOR2 world_viewport;
#pragma endregion Toi uu hoa

public:
	FWGraphic(FWGame* fwGame);
	bool init();
	void clear(D3DCOLOR color);
	void begin();	
	void begin(D3DXMATRIX* tranform);	

	//Ve texture tai position voi width va height cua texture, su dung transform
	void tDraw(FWTexture* texture,D3DXVECTOR2 position,D3DXVECTOR2 center, D3DCOLOR color);
	//Ve texture tai destRect. su dung transform
	void tDraw(FWTexture* texture,RECT destRect,D3DXVECTOR2 center, D3DCOLOR color);
	//Ve mot phan texture tai destRect. phan nay duoc cat ra tu texture boi sourRect. su dung transform
	void tDraw(FWTexture* texture,RECT sourRect,RECT destRect,D3DXVECTOR2 center, D3DCOLOR color);					

	//Ve texture tai position voi width va height cua texture 
	void nDraw(FWTexture* texture,D3DXVECTOR2 position,D3DXVECTOR2 center, D3DCOLOR color);
	//Ve texture tai destRect 
	void nDraw(FWTexture* texture,RECT destRect,D3DXVECTOR2 center, D3DCOLOR color);
	//Ve mot phan texture tai destRect. phan nay duoc cat ra tu texture boi sourRect
	void nDraw(FWTexture* texture,RECT sourRect,RECT destRect,D3DXVECTOR2 center, D3DCOLOR color);	
	bool initFont();
	void sDraw(char* text, D3DXVECTOR2 pos, D3DCOLOR color);
	void SetFontSize(D3DXVECTOR2 size);
	void end();	
	~FWGraphic(void);
};

